   /\
  /__\=================================================================
 /\  /\   ****** VITAL DUNGEON HEX DATA (WRITTEN BY PUZZLEDUDE) ******
/__\/__\===============================================================

All hex offsets are for a NON-headered rom and for Zelda3 A link to the Past.
Hacks can have the data shifted!



***********************************************
1.) ROOM DATA   (Object data for Bg1, Bg2, Bg3)
***********************************************

-bank not fixed (can be realocated)
-3 byte pointers

*Primary pointers at:
1. 8746, 01 80 1F --> F8001   \
2. 874C, 00 80 1F --> F8000    \ is F8000
3. 883F, 01 80 1F --> F8001    /
4. 8845, 00 80 1F --> F8000   /

For realocation change all pointers accordingly.


*Secondary pointers at:
F8000 (block is 3C0) = 960 in dec => 960:3 = 320 --> for 320 rooms (room 0 to room 319)

(3 byte pointers for one room)


*Pointer Read
6A 84 0A = reversed 0A 84 6A --> points to 5046A (address calculator needed for determine this)
E2 90 0A = reversed 0A 90 E2 --> points to 510E2
etc

*Room code
start (pointer points to it)....bg1....FF FF.....bg2.....FF FF......bg3......FF FF. (end)

Data are objects: x position, y position, size, type.
Data holds room layout (2nd byte) and floor1 and floo2 value (1st byte).


*No bg2
start (pointer points to it)...bg1...FF FF FF FF......bg3......FF FF. (end)


*No bg3
start (pointer points to it)...bg1...FF FF.....bg2.....FF FF FF FF. (end)


*Empty room
start (pointer points to it)...bg1 basic data...FF FF FF FF FF FF. (end)


*End of room data is always the third FF FF value after pointer!
(there are some minor exceptions though).


*All poitners are 3bytes long = full address can be defined. Realocation of room data
to anywhere between 0 and 400000 is possible.
Realocation of secondary pointers is also possible. 
Realocation Not compatible to Hyrule Magic.








***********************************************
2.) SPRITE DATA, INDOORS
***********************************************

-the global bank is somehow stuck at 40000.

*Primary pointer at:
4C298, but 2 bytes only = 2E D6
code is B9 2E D6 85 00 AD 8E 04 4A, No third value 09, to make it 2E D6 09 = 09 D6 2E = 4D62E.
no value is 09 to define 40000. If anyone can find the value, which defines 40000, let me know.

*Secondary pointers at:
4D62E (block is 300) = in dec is 768:2 = 384 (for 320 room + some additional data).

*Data is at:
4D92E (block is 1371) = ends at 4EC9E


*Pointer read:
2E D9 = reversed D9 2E = 09 D9 2E --> points to 4D92E = room 0.


*Sprite Code
for room 0 = Ganon
00 05 17 D6 FF, sort sprite is 00, y = 05, x = 17, type = D6-Ganon, FF = end.

The 05 is not only y coordinate, but also: if the sprite is on bg1 or bg2.


*Empty room (no sprites)
00 FF


Comparisment to Goddess of Wisdom hack
bank shifted, at 4C298 is DB CE, so sec. pointers at 4CEDB
but data end also at 4EC9E.

Comparisment to Parallel Worlds hack
bank shifted, at 4C298 is 6C D4, so sec. pointers at 4D4C6
but data end also at 4EC9E.

So sprites can not be seen in HM for PW, because they were shifted.



UPDATE on how to transfer the Sprites to another bank
*****************************************************

0.) Expand the rom to 2MB (go to 100000 and add another 100000 bytes).


1.) Go to 4D62E and select block 1671 in hex. Copy the selection first, then fill
selection with FF bytes. Go to 14D62E and paste/rewrite.


2.) At 04C296: pointer to the new code at 14C296 (address can be changed)
A8 B9 2E D6 --> 22 96 C2 29


3.) At 14C296: new code written by Conn
E2 30 A9 29 48 AB C2 30 AD 8E 04 0A A8 B9 2E D6 6B

4th byte (29) controls the global bank (can be changed).
15th and 16th byte (2E D6) control the local address (can be changed).
Together is 2E D6 29 = 29D62E (snes) = 14D62E (pc)

All secondary pointers are local (so pointers + data have 8000 bytes of space,
before it was 1671).







***********************************************
3.) ITEM DATA, INDOORS
***********************************************

-These are red dots in HM, to define stuff under jars (heart, magic, key, bomb etc)


*Primary pointer at E6C1
Code BF 69 DB 01, 85 00, A9 01

69 DB 01 points to DB69

01 defines the global bank. Can be realocated anywhere between 0 and 400000.
For instance BF 69 DB 23, 85 00, A9 23; new address is 11DB69.


*Secondary pointers at:
DB69 (block is 282), 282 is 642 in dec :2 = 321 rooms (for 320 rooms + 2 bytes)

*Data at:
DDEB (block is 8C7)


*Pointer read
EB DD reversed is DD EB = direct address = DDEB


*Item code
CE 13 0B FF FF, CE = x, 13 = y, 0B = type, FF FF = end

A jar object is necessary at the same location for the item to work!








***********************************************
4.) INDOOR PUSHABLE BLOCKS
***********************************************

*Number of bytes to define block data at:
8896,
default is 8C 01 = 18C = 396 bytes :4 =  99 blocks, but
maximum is 00 02 = 200 = 512 bytes :4 = 128 blocks (29 more).

max was tested, 04 02 = block not displayed, too much data.
So 80 in hex for one pointer is max.

*Primary pointers at:
1. 15AFA, DE F1 04, -->  271DE (but with hardcoded block = 80)
2. 15B01, 5E F2 04, -->  2725E (but with hardcoded block = 80)
3. 15B08, DE F2 04, -->  272DE (but with hardcoded block = 80)
4. 15B0F, 5E F2 04, -->  2735E (but with hardcoded block = 0C by default, 80 max)

Pointers can be changed to another place, but it will only read the 80 bytes in hex
after this location.


*No secondary pointers, but Data directly at:

271DE (block is 80+80+80+0C) = 18C = 396 in dec :4 = 99 pushable blocks.
max block is 80 x 4 = 200 in hex.

*Code (4bytes for one block)
0B 01 3A 19 (no ending value! FF), room values are mixed!, so the space must be hardcoded, that
the game knows where to stop reading values.

0B 01 is 10B = room 267. 3A is x, 19 is y.

Want to insert a block in hex, lets say the x=08, y=0A in Hyrule Magic.

x times 2       is 08 x 2 = 10 in hex
y divided by 2  is 0A : 2 = 05 in hex

So x value will always be bigger than y.


lets take room 80 for instance, 80 is 50 in hex.

new code is 50 00 10 05 for block in room 80, on HM coordinates x=08, y=0A.


NOTE on expansion
*****************
Blocks can not be expanded over 4x80, because all blocks go to ram when indoors.





***********************************************
5.) INDOOR TORCHES
***********************************************


*Number of bytes to define torch data at:
88C1,
default is 2C 01 = 288 bytes, but
maximum is 80 01 = 384 bytes. (around 28 torches more)

max was tested, 8C 01 crashes the game, too much data for torches.
So 80 in hex for one pointer is max.

*Primary pointers at:
1. 15B16, 6A F3 04 = 04 F3 6A = 2736A (block 80)
2. 15B1D, EA F3 04 = 04 F3 EA = 273EA (block 80) 
3. 15B24, 6A F4 04 = 04 F4 6A = 2746A (block 20, max 80)

If 04 is changed to 24, new data is at 12736A and at 88C1 to 80 01,
the block can be 384 bytes long.


*No secondary pointers, but Data directly at:

2736A (block is 80+80+20) = 12C = 288 in dec.
max block is 180 in hex

1 torch in a new room is 6 bytes, then +2 bytes for each torch.
2 torches is 8bytes, 3 is 10 and 4 is 12 etc.


*Code (example)
43 00, AA 03, B6 03, AA 09, B6 09, FF FF

43 00 = room 67,
AA is x, 03 is y for the first torch
B6 is x, 03 is y for the second torch etc
FF FF is end.

The upper room has 4 torches.


NOTE on expansion
*****************
Torches can not be expanded over 3x80, because all torches go to ram when indoors.






***********************************************
6.) ROOM HEADER PROPERTIES
***********************************************


*Primary pointer at B5DC
Code BF, 02 F5 04, 85 0D, E2 20 C2 10, A9 04

02 F5 04 points to 27502

04 defines the global bank. Can be realocated anywhere between 0 and 400000.
For instance BF, 02 F5 24, 85 0D, E2 20 C2 10, A9 24; new address is 127502.


*Secondary pointers at:
27502 (block is 280)

*Data at:
27782 (block is 87E)

*Pointers + data
27502 (block is AFE)

*Pointer read
82 F7 = F7 82 = 04 F7 82 = 27782


*Header code (14 bytes maximum)

1st byte,
bg properties + collision

2nd byte,   3rd byte,   4th byte,   5th byte,     6th byte,   7th byte
PAL         BLK         EnemyBLK    Room effect   Tag1        Tag2


8th byte
Plane properties for hole/warp and staircase 1, 2, 3

9th byte
Plane properties for staircase 4

10th byte,   11th byte,    12th byte,    13th byte,    14th byte.
hole/warp    staircase1    staircase2    staircase3    staircase4.

This is essentialy related to room transit values as a part of a room header.







***********************************************
7.) CHEST DEFINITIONS
***********************************************


*Primary pointer at:
1. EBFB, 6E E9 01 = E96E
2. EC0A, 70 E9 01 = E970
3. EC10, 6E E9 01 = E96E   all for E96E

Repoint all 3 accordingly. 01 to 23 is 11E96E for instance.

max bank is 1F8 = 504 in dec : 3 for one chest = 168 chests possible in the game.


*No secondary pointers, but Data directly at:
E96E (block is 1F8)


*Code is (3 bytes for one chest definition)
04 00 23,  04 00 = room 4, 23 is a content of the chest.
                           23 in hex is 35 in dec is 35: Armor 3 in Hyrule magic.

04 80 23,  04 00 = room 4, but 80 is big chest, 23 is Armor 3.

04 01 23,  04 01 is 104 in hex is room 260, 23 is Armor 3.


*Definition will only work with the chest object in the same room!

*Problems
Sometimes the definition is set, but no chest object is inserted. Insert chest in the rooms
with chest definitions to solve this problem.



UPDATE on how to expand the chest definitions
*********************************************
I've just found the expansion for chests!  
It is at EBF6! just before EBFB (pointer). Currently it is F8 01, so reversed 01F8.
I've expanded this to 1C 02 is 21C, put the chest at the end, and it works.
Expanded spece must be dividable with 3. So 1F8+3+3+3+3...
Max with two bytes is FF FF= can be divided
with 3. FFFF= 65.535 :3, is 21.845 chests possible in theory.






***********************************************
8.) INDOOR DAMAGE PITS
***********************************************


*Couldnt find any pointers here


*Data at 190C (block is fixed to 72)

72 in hex is 114 in dec :2 = 57 rooms with pits are possible.

2 bytes for a pit definition.

*Code
72 00 = room 114

No pointers, fixed location and block size. No FF ending, just a list of rooms in hex.


UPDATE
******
#define ROOM_PITS_POINTER_LOCATION 0x394AB
#define ROOM_PITS_DATALENGTH_VALUE_LOCATION 0x394A6

Pointer at 394AB, pointer is 0C 99 00, leads to 00190C.
Datalength at 394A6, 70 00 (+02 is 72 00 is 72 in hex is 114 in dec :2 =57 rooms with pits.
This can now be expanded to 320. 320 rooms x2 = 640, is 280in hex= 80 02= (-2) = 7E 02.
change 70 00 into 7E 02 to be able to have all 320 rooms with hurt pits.




***********************************************
9.) INDOOR TELEPATIC MESSAGES
***********************************************

*Couldnt find any pointers here


*Data at 3F61D (block is fixed to 280)

280 in hex is 640 in dec :2 = for 320 rooms. Rooms go from 0-319.

2 bytes for a message definition.

*Code
72 00 = message (monologue number) 114

No pointers, fixed location and block size. No FF ending, just a list of message values in hex.


UPDATE
******
Pointers were found. Complex to move, similar to sprites. Data realocation not necessary.
All 320 rooms can have a different telepatic message already by default. Moving data or
expanding the datalength is not necessary.





***********************************************
10.) BASIC STARTING LOCATION PROPERTIES
***********************************************


A) Wall blockset for entrances
15381 (block is 85 for 85 entrances in hex)


B) Music definitions for entrances
1582E (block is 85 for 85 entrances in hex)


A) Dungeon definition for entrances
1548B (block is 85 for 85 entrances in hex)

FF is no dungeon or None. Hyrule magic can make a false byte FE,
change it manually to FF to fix this.


-----------------------

After the repointing of any data the file is no longer compatible to Hyrule Magic!
The addresses are fixed in Hyrule Magic. The program will not read new pointers!





***********************************************
11.) THE USE OF THIS DOCUMENT
***********************************************

-repointing data,
-porting data between games,
-having more room for data,
-make use of rooms 296-319,
etc



   /\
  /__\=================================================================
 /\  /\   ****** VITAL DUNGEON HEX DATA (WRITTEN BY PUZZLEDUDE) ******
/__\/__\===============================================================


